﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ThreeByte.ActiveDeck.Config;
using System.Windows.Forms.Integration;
using ThreeByte.ActiveDeck.AddIn.Controls;

namespace ThreeByte.ActiveDeck.Controls
{
    public partial class HostForm : Form
    {
        public HostForm(System.Windows.Controls.UserControl userControl) {
            InitializeComponent();

            if(userControl is ICloseable) {
                ((ICloseable)userControl).Close += new EventHandler<DialogResultEventArgs>(fromsControl_Close);
            }
            //Add Setup Form
            ElementHost elementHost = new ElementHost();
            elementHost.Dock = DockStyle.Fill;
            elementHost.Location = new Point(0, 0);
            elementHost.Name = "elementHost";
            elementHost.Child = userControl;
            elementHost.AutoSize = true;
            this.Controls.Add(elementHost);

            this.ClientSize = new System.Drawing.Size((int)(userControl.MinWidth), (int)(userControl.MinHeight));
            string titleOverride = userControl.Tag as string;
            if(!(string.IsNullOrEmpty(titleOverride))) {
                this.Text = titleOverride;
            }
            
        }

        void fromsControl_Close(object sender, DialogResultEventArgs e) {
            this.DialogResult = e.DialogResult;
        }

        private void HostForm_FormClosing(object sender, FormClosingEventArgs e) {
            
        }
    }
}
